package com.zy.explore.license.infrastructure.result;

import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import javax.validation.Valid;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;

/**
 * AutoResultVO 自动配置属性
 *
 * @author administrator
 * @since 2020/8/28
 */
@Component
@Data
@Valid
@ConditionalOnProperty(value = ResultVOConfigurer.ENABLED, matchIfMissing = true)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConfigurationPropertiesScan(ResultVOConfigurer.PREFIX)
@Import(value = { ResultVODecoder.class, ResultVOAdvice.class })
class ResultVOConfigurer {

    static final String PREFIX = "common.auto-result-vo";
    static final String ENABLED = PREFIX + ".enabled";

    /**
     * 需要排除的路径
     */
    @Valid
    private final List<@NotBlank String> excludePath = new ArrayList<>();
    /**
     * 是否开启自动 ResultVO
     */
    @AssertTrue
    private Boolean enabled = true;
}